<template>
	<view>
		<block v-for="(ite,index) in newsList">
			<view class="list flex flex-direction align-center justify-between">
				<text>{{ite.addtime}}</text>
				<view class="myCard flex flex-direction">
					<view class="flex align-center">
						<text>{{ite.title}}</text>
					</view>
					<view>
						<u-parse :content="ite.content"></u-parse>
					</view>
				</view>
			</view>
		</block>
		<view class="flex solid-bottom padding justify-center">
			<text class="loadMore">{{loadStr}}</text>
		</view>
	</view>
</template>

<script>
	import uParse from '@/components/u-parse/u-parse.vue'
	var api = require('@/components/api.js');
	export default {
		comments:{
			uParse
		},
		data() {
			return {
				refreshing: false,
				loadStr:'加载中...',
				fetchPageNum: 1,
				newsList:[],
			}
		},
		onLoad(){
			this.loadMyNews()
		},
		onReachBottom() {
			console.log('滑动到页面底部')
			this.loadMyNews();
		},
		onPullDownRefresh() {
			console.log('下拉刷新');
			this.refreshing = true;
			this.loadMyNews();
		},
		methods: {
		loadMyNews: function() {
			try {
				var userId = uni.getStorageSync('user').user_id;
				api.get({
					url: 'User/GetMessageList',
					data: {
						user_id: userId,
						page: this.refreshing ? 1 : this.fetchPageNum,
						pagesize: 30
					},
					success: data => {
						console.log(data)
						if (data.ErrCode == 0) {
							this.newsList = data.Response
							this.refreshing = false;
							uni.stopPullDownRefresh();
							this.loadStr = ''
						} else if (data.ErrCode == 2) {
							if (data.ErrMsg == '暂无内容') {
								this.refreshing = false;
								uni.stopPullDownRefresh();
								this.loadStr = '已经到底了'
								return;
							}
						}
					}
				});
			} catch (e) {
				uni.showModal({
					title: '提示',
					content: '账号超时，请重新登陆',
					success: (res) => {
						if (res.confirm) {
							uni.navigateTo({
								url: '/pages/login/login'
							});
						}
					}
				});
			}
		},	
		}
	}
</script>

<style>
	.list>text{
			font-size: 24upx;
			color: #999999;
			line-height: 92upx;
	}
	.myCard>view:nth-child(2)>text{
		font-size: 26upx;
			color: #666666;
	}
	.myCard>view:nth-child(2){
		padding-top: 20upx;
		box-sizing: border-box;
	}
	.myCard>view:nth-child(1){
		border-bottom: 1upx solid #ddd;
		height: 86upx;
	}
	.myCard>view:nth-child(1)>text{
		font-size: 30upx;
		color: #000000;
	}
	.myCard{
		padding: 0 20upx;
		box-sizing: border-box;
		width: 710upx;
		height: 220upx;
		background-color: #fff;
	}
</style>
